Use case: COMP comparing by polling

Description of usage

Operation

HAL1

HAL2

Start comparing

Activate Comparator analog features using:

  • HAL_COMP_Start().

Activate Comparator analog features using HAL_COMP_Start().

Retrieve comparing result

Retrieve comparing results using:

  • HAL_COMP_GetOutputLevel().

Retrieve comparing results using:

  • HAL_COMP_GetOutputLevel().

Loop for multiple iterations

Possible multiple iterations if the comparator output has changed since the last read.

Possible multiple iterations if the comparator output has changed since the last read.

Stop comparing

Stop Comparator analog features using:

  • HAL_COMP_Stop().

Stop Comparator analog features using HAL_COMP_Stop().

Sequence diagram

@startuml
title: COMP basic operation using programming model: polling

participant "User Application" as appli
participant "<font color=green><b>HAL COMP</b></font>" as COMP
participant "HAL EXTI" as EXTI

group#Bisque #Linen COMP operation
appli->COMP : HAL_COMP_Start()
COMP->COMP : Activate comparator analog features
COMP->appli

loop#lightgrey Possible multiple iterations

appli->COMP : HAL_COMP_GetOutputLevel()
COMP --> appli: Logical level high/low
end

appli->COMP : HAL_COMP_Stop()
return

end

@enduml

Code snippet

HAL1 / HAL2

uint32_t comp_output_register_state = HAL_COMP_OUTPUT_LEVEL_LOW;

/*initialize and configure your comparing input*/

/* Start the COMP  */
HAL_COMP_Start(&comp1);

while(comp_output_register_state == HAL_COMP_OUTPUT_LEVEL_HIGH)
{

  /* generate voltage on comparator inputs */

  /* add a Wait time for voltage stabilization*/

  /* Check comparator output: digital flag */
  comp_output_register_state = HAL_COMP_GetOutputLevel(&comp1);

}
/* Stop the COMP  */
HAL_COMP_Stop(&hcomp1);

Key changes

  1. No major changes between HAL1 and HAL2.